/*
 * Observer.h
 *
 *  Created on: 20 déc. 2011
 *      Author: M. Alexandre (malexand314@gmail.com)
 */

#ifndef OBSERVER_H_
#define OBSERVER_H_

#include <list>
#include "pthread.h"

/*
 *
 */
namespace Framework
{
    class Observer;

    class ObserverSubject
    {
        protected:
            ObserverSubject();
        public:
            virtual ~ObserverSubject();

        public:
            void attachObserver(Observer* _ptObserver);
            void detachObserver(Observer* _ptObserver);

        protected:
            void notify();
            virtual void updateState() = 0;

        private:
            std::list<Observer*> m_listObserver;
            pthread_mutex_t m_observerMutex;
    };

    class Observer
    {
        public:
            virtual ~Observer() { }

        public:
            virtual void update(ObserverSubject* _ptSubject) = 0;

        protected:
            Observer() { }
    };

}

#endif /* OBSERVER_H_ */
